/**
 * @author free
 * @version 1.0
 * @since 2021/12/06 09:22
 */
package com.menhai.personmanagement.services;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.menhai.personmanagement.entity.MbCommonRecord;
import com.menhai.personmanagement.mapper.MbCommonRecordMapper;

@Service
public class MbCommonRecordService {
	
		@Autowired
	    private MbCommonRecordMapper mbCommonRecordMapper;

	  	@Transactional
	  	public Map<String, Object> add(MbCommonRecord mbCommonRecord) {
	  		Map<String,Object> resultMap = new HashMap<String,Object>();
	  		try{
	  			int iRet = mbCommonRecordMapper.insert(mbCommonRecord);
	  			if(iRet == 0){  //没有插入成功的数据
	  				resultMap.put("success", "0");
	  				resultMap.put("message", "插入成功的条数为0，新建每日健康生活记录失败！");
	  				return resultMap;
	  			}else{
	  				resultMap.put("success", "1");
	  				resultMap.put("message", "新建每日健康生活记录成功！");
	  				return resultMap;
	  			}
	  		}catch(Exception e){
	  			resultMap.put("success", "0");
	  			resultMap.put("message", "新建日常记录失败！异常：" +e.getMessage());
	  			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
	  		}
	  		return resultMap;
	  	}
	  	
	  	@Transactional
	  	public Map<String, Object> edit(MbCommonRecord mbCommonRecord) {
	  		Map<String,Object> resultMap = new HashMap<String,Object>();
	  		try{
	  			int iRet = mbCommonRecordMapper.update(mbCommonRecord);
	  			if(iRet == 0){  //没有插入成功的数据
	  				resultMap.put("success", "0");
	  				resultMap.put("message", "编辑成功的条数为0，编辑每日健康生活记录失败！");
	  				return resultMap;
	  			}else{
	  				resultMap.put("success", "1");
	  				resultMap.put("message", "编辑每日健康生活记录成功！");
	  				return resultMap;
	  			}
	  		}catch(Exception e){
	  			resultMap.put("success", "0");
	  			resultMap.put("message", "编辑每日健康生活记录失败！异常：" +e.getMessage());
	  			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
	  		}
	  		return resultMap;
	  	}
	  	

		@Transactional
		public Map<String, Object> deleteById(String id) {
			Map<String,Object> resultMap = new HashMap<String,Object>();
			try{	
				int iRet = mbCommonRecordMapper.delete(id);
				if(iRet == 0){  
					resultMap.put("success", "0");
					resultMap.put("message", "删除成功的条数为0，删除每日健康生活记录失败！");
					return resultMap;
				}
				resultMap.put("success", "1");
				resultMap.put("message", "删除每日健康生活记录成功！");
			}catch(Exception e){
				resultMap.put("success", "0");
				resultMap.put("message", "删除每日健康生活记录失败！异常：" +e.getMessage());
				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			}
			return resultMap;
		}
		

		public List<Map<String,Object>> getListByCondition(MbCommonRecord mbCommonRecord) {
			return mbCommonRecordMapper.getListByCondition(mbCommonRecord);
		}
		
		
		public IPage<MbCommonRecord> getListByConditionByPage(MbCommonRecord mbCommonRecord){
	        Page<MbCommonRecord> page = new Page<>(mbCommonRecord.getPageIndex(),mbCommonRecord.getPageSize());
	        return mbCommonRecordMapper.getListByConditionByPage(page,mbCommonRecord);
	    }
		
		/**
		 * 获取随访记录列表
		 * @param getOneById
		 * @return List<Map>
		 */
		public List<Map<String,Object>> getOneById(MbCommonRecord mbCommonRecord) {
			return mbCommonRecordMapper.getOneById(mbCommonRecord);
		}
	
}
